﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using SDService.Common;
namespace SDService.Model.DTO
{
    public class ResponseBase
    {
        public bool Success { get; set; }
        public string Message { get; set; }
        public string Code { get; set; }

        public ResponseBase()
        {
            Success = true;
            Message = "成功";
            Code = "30000";
        }

        public ResponseBase(int code)
        {
            Message = SystemConstant.GetValue(code.ToString());
            if (Message.Equals("未定义的错误"))
                Code = "30300";
        }

        public ResponseBase(int code, string msg)
        {
            Code = code.ToString();
            Message = msg;
        }

        public static ResponseBase Succeed()
        {
            return new ResponseBase();
        }

        public static T Succeed<T>() where T : ResponseBase
        {
            return (T)Activator.CreateInstance(typeof(T));
        }

        public static T Error<T>() where T : ResponseBase
        {
            T response = (T)System.Activator.CreateInstance(typeof(T));
            response.Code = "30300";
            response.Message = SystemConstant.GetValue("30300");
            response.Success = false;
            return response;
        }


        public static T Error<T>(string code,string msg) where T : ResponseBase
        {
            T response = (T)System.Activator.CreateInstance(typeof(T));
            response.Code = code;
            response.Message = msg;
            response.Success = false;
            return response;
        }

        public static T Error<T>(int code) where T : ResponseBase
        {
            T response = (T)System.Activator.CreateInstance(typeof(T));
            response.Code = code.ToString();
            response.Message = SystemConstant.GetValue(code.ToString());
            response.Success = false;
            return response;
        }

        public static T Error<T>(int code, string msg) where T : ResponseBase
        {
            T response = (T)System.Activator.CreateInstance(typeof(T));
            response.Code = code.ToString();
            response.Message = msg;
            response.Success = false;
            return response;
        }
    }

    public class ArrayResultResponseBase<T> : ResponseBase
    {
        public int Total { get; set; }

        public List<T> Result { get; set; }

    }

    public class ArrayResultResponseBase : ResponseBase
    {
        public int Total { get; set; }

        public IList Result { get; set; }

    }

    public class ResultResponseBase : ResponseBase
    {
        public object Result { get; set; }

    }
    //ArrayResultResponseBase  ResultResponseBase
    public class ResultResponseBase<T> : ResponseBase
    {
        public T Result { get; set; }

        public ResultResponseBase()
        {
        }
        public ResultResponseBase(T result)
        {
            Result = result;
        }
    }
}
